package com.ppt.convert.controller;

import com.ppt.convert.domain.Result;
import com.ppt.convert.entity.Convert;
import com.ppt.convert.service.PdfConvertService;
import com.ppt.convert.service.PptConvertService;
import com.ppt.convert.service.WordConvertService;
import org.apache.commons.lang.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.Map;

/**
 * @author zcx https://blog.csdn.net/u012453843/article/details/52953812
 * @Title ppt转化控制层
 * @date 2020年01月19日 15:54
 **/
@RestController
@RequestMapping(value = "/convert")
public class FileConvertController {

    @Autowired
    private PptConvertService pptConvertService;

    @Autowired
    private PdfConvertService pdfConvertService;

    @Autowired
    private WordConvertService wordConvertService;
    /**
     * ppt转化接口
     * @author zcx
     * @date 2020-07-01 09:56
     * @param convert
     * @return com.ppt.convert.domain.Result
     */
    @RequestMapping(value = "/ppt", method = RequestMethod.POST, produces = "application/json")
    public Result pptConvert(@RequestBody Convert convert) {
        if (StringUtils.isEmpty(convert.getDentryId())||StringUtils.isEmpty(convert.getCompanyId())
                || StringUtils.isEmpty(convert.getFileUrl())||StringUtils.isEmpty(convert.getFileName())){
            return Result.failed("缺少参数");
        }
        return pptConvertService.pptConvert(convert.getDentryId(),convert.getCompanyId()
                ,convert.getFileUrl(),convert.getFileName());
    }

    /**
     * ppt转化接口
     * @author zcx
     * @date 2020-07-01 09:56
     * @param convert
     * @return com.ppt.convert.domain.Result
     */
    @RequestMapping(value = "/pdf", method = RequestMethod.POST, produces = "application/json")
    public Result pdfConvert(@RequestBody Convert convert) {
        if (StringUtils.isEmpty(convert.getDentryId())||StringUtils.isEmpty(convert.getCompanyId())
                || StringUtils.isEmpty(convert.getFileUrl())||StringUtils.isEmpty(convert.getFileName())){
            return Result.failed("缺少参数");
        }
        return pdfConvertService.pdfConvert(convert.getDentryId(),convert.getCompanyId()
                ,convert.getFileUrl(),convert.getFileName());
    }

    /**
     * ppt转化接口
     * @author zcx
     * @date 2020-07-01 09:56
     * @param convert
     * @return com.ppt.convert.domain.Result
     */
    @RequestMapping(value = "/word", method = RequestMethod.POST, produces = "application/json")
    public Result wordConvert(@RequestBody Convert convert) {
        if (StringUtils.isEmpty(convert.getDentryId())||StringUtils.isEmpty(convert.getCompanyId())
                || StringUtils.isEmpty(convert.getFileUrl())||StringUtils.isEmpty(convert.getFileName())){
            return Result.failed("缺少参数");
        }
        return wordConvertService.wordConvert(convert.getDentryId(),convert.getCompanyId()
                ,convert.getFileUrl(),convert.getFileName());
    }
}
